package com.example.user.myzzyl_android;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class XianLuActivity extends AppCompatActivity {
    List<String> data = new ArrayList<>();
    ListView listView;
    List<String> text = new ArrayList<>();
    JsonText3 jsonText3;
    XianLuAdpter xianLuAdpter;
    @BindView(R.id.btn_showSideMenuss)
    ImageButton btnShowSideMenuss;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xian_lu);
        ButterKnife.bind(this);
        listView = (ListView) findViewById(R.id.list_item2);

        OkGo.<String>post("http://zhihui.expo2017.net.cn/zzwhe/resources/tjlx/list")
                .tag(this)
                .params("page", 1)
                .params("size", 5)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Log.i("bbbbbb", response.body());
                        jsonText3 = JSON.parseObject(response.body(), JsonText3.class);
                        for (int i = 0; i < jsonText3.getData().getContent().size(); i++) {
                            data.add("http://zhihui.expo2017.net.cn/zzwhe/" + jsonText3.getData().getContent().get(i).getTp());
                            text.add(jsonText3.getData().getContent().get(i).getJs());
                        }
                        xianLuAdpter.notifyDataSetChanged();
                    }
                });
        xianLuAdpter = new XianLuAdpter(this, data, text);
        listView.setAdapter(xianLuAdpter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                intent.putExtra("url", "http://zhihui.expo2017.net.cn/zzwhe/zzwhe/tjlxlx/details/" + "?id=" + jsonText3.getData().getContent().get(i).getId());
                startActivity(intent.setClass(XianLuActivity.this, XiangQing.class));
            }
        });
    }

    @OnClick(R.id.btn_showSideMenuss)
    public void onViewClicked() {
        finish();
    }
}
